package com.shark.stock.mock
{
	import com.shark.stock.vos.Article;
	import com.shark.stock.vos.Category;
	
	import mx.collections.ArrayCollection;

	public class StockMockServices
	{
		
		private var stock:ArrayCollection;
		
		public function StockMockServices()
		{
			
		}
		
		public function getCategories():ArrayCollection{
			var cats:ArrayCollection  = new ArrayCollection();
			for(var i:int=1;i< 20;i++){
				var cat:Category = new Category();
				cat.id = i;
				cat.description = "The "+i+" category";
				cats.addItem(cat);
			}
			return cats;
		}
		
		public function getStock():ArrayCollection{
			if(stock == null){
				stock = new ArrayCollection();
				for(var i:int=1;i<10;i++){
					var art:Article = new Article();
					art.id = i;
					art.name = "Articulo "+i;
					art.price = Number(i * 23);
					art.category =  new Category();
					art.category.id = i;
					art.category.description = "The "+i+" category";
					stock.addItem(art);
				}
			}
			return stock;
		}
		
		public function saveArticle(article:Article):Boolean{
			if(article.id == 0){
				article.id = stock.length+1;
				stock.addItem(article);
			}
			trace("article remotelly saved");
			return true;
		}
	}
}